package main

import (
	"errors"
	"fmt"
)

// TODO: IP + PORT
type Connection struct {
}

// stuffclient  interface do something
type StuffClient interface {
	DoStuff() error
}

// stuffclient
type stuffClient struct {
	conn    Connection
	timeout int
	retries int
}

// 实现StuffClient 接口
func (s stuffClient) DoStuff() error {
	fmt.Println("do something:", s)

	return errors.New("don't  something")
}

type StuffClientOption func(*stuffClient)

func WithRetries(r int) StuffClientOption {
	return func(o *stuffClient) {
		o.retries = r
	}
}
func WithTimeout(t int) StuffClientOption {
	return func(o *stuffClient) {
		o.timeout = t
	}
}

var defaultStuffClientOptions = stuffClient{
	retries: 3,
	timeout: 2,
}

func NewStuffClient(conn Connection, opts ...StuffClientOption) StuffClient {
	options := defaultStuffClientOptions
	for _, o := range opts {
		o(&options)
	}
	options.conn = conn
	return options

}

func main4() {

	a := NewStuffClient(Connection{}, WithRetries(2), WithTimeout(10))
	fmt.Println(a)
}
